import os, thread, socket, string, sys, DescriptionParser;
from SubmitNewExps import *


def readAndSubmitExp(experimentDescriptionFile):
    file = open(experimentDescriptionFile);
    lines = file.readlines();
    expName = lines[0].strip();
    print "Experiment Name " + expName;
    #factors
    sfactors = string.split(lines[1]);
    factors = [];
    if(lines[1].find("all")>=0):
        factors = DescriptionParser.getFactors(expName);
    else:
        sys.stdout.write("Factors: ")
        for sfactor in sfactors:
            factors.append(string.atoi(sfactor));   
            sys.stdout.write(sfactor)
    print "";
    numOfExperiments = string.atoi(lines[2].strip());
    print "Number of Experiments %d"%numOfExperiments;
    
    servername = lines[3].strip();
    print "Run Experiments in " + servername;
    
    ipAddress = lines[4].strip();
    print "Server address " + ipAddress;

    submitExps(expName, factors, numOfExperiments, servername, ipAddress)

if __name__ == "__main__":
    if(len(sys.argv) == 2):
        readAndSubmitExp(sys.argv[1])
    else:
        print "Usage: python UserInterface.py Path_Of_Description_File";
        
    